package frist50;

import org.junit.jupiter.api.Test;

public class T0033 {
    public int search(int[] nums, int target) {
        int len = nums.length;
        return find(nums, 0, len - 1, target);
    }

    public int find(int[] nums, int left, int right, int target) {
        if (left > right) return -1;
        int mod = left + (right - left) / 2;
        int modvalue = nums[mod];
        if (nums[mod] == target) return mod;
        int zero = nums[left];
        if (target < zero && zero <= modvalue) {
            return find(nums, mod + 1, right, target);
        }
        if (modvalue < zero && zero <= target) {
            return find(nums, left, mod - 1, target);
        }
        if (target > modvalue) {
            return find(nums, mod + 1, right, target);
        } else {
            return find(nums, left, mod - 1, target);
        }
    }

    @Test
    public void test() {
        int[] nums = {4, 5, 6, 7, 0, 1, 2};
        int target = 0;
        System.out.println(search(nums, target));
    }
}
